home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 414_02 / nonport / wbox.c < prev    next >
C/C++ Source or Header  |  1993-06-17  |  6KB  |  236 lines

  1. #define    CURSES_LIBRARY    1
  2. #include <curses.h>
  3. #undef    wbox
  4.  
  5. #ifdef PDCDEBUG
  6. char *rcsid_wbox = "$Header: C:\CURSES\nonport\RCS\wbox.c 2.1 1993/06/18 20:22:23 MH Rel MH $";
  7. #endif
  8.  
  9. /*man-start*********************************************************************
  10.  
  11.   wbox()    - draw box
  12.  
  13.   PDCurses Description:
  14.      Draws a box in window 'win', enclosing the area xmin-xmax and
  15.      ymin-xmax. If xmax and/or ymax is 0, the window max value is
  16.      used. 'v' and 'h' are the vertical and horizontal characters
  17.      to use.     If 'v' and 'h' are PC grapics lines, wbox will make
  18.      the corners in a pretty way.
  19.  
  20.          Single Bar Box            Double Bar Box
  21.      ----------------------        ======================
  22.      (0xDA)    (0xC4)    (0xBF)        (0xC9)    (0xCD)    (0xBB)
  23.        +      -      +          +      =      +
  24.        | (0xB3)        |          || (0xBA)     ||
  25.        +      -      +          +      =      +
  26.      (0xC0)        (0xD9)        (0xC8)        (0xBC)
  27.  
  28.      PC Graphic Graphic Character Solids:
  29.          # (quarter-tone)    (0xB0)
  30.          # (half-tone)        (0xB1)
  31.          # (three-quarter-tone)    (0xB2)
  32.          # (solid)        (0xDB)
  33.  
  34.   PDCurses Return Value:
  35.      The wbox() function returns OK on success and ERR on error.
  36.  
  37.   PDCurses Errors:
  38.      No errors are defined for this function.
  39.  
  40.   Portability:
  41.      PDCurses    int wbox( WINDOW* win,  int ymin, int xmin,
  42.                          int ymax, int xmax,
  43.                          chtype v,   chtype h );
  44.      BSD Curses
  45.      SYS V Curses
  46.  
  47. **man-end**********************************************************************/
  48.  
  49. int    wbox(WINDOW *win,int ymin,int xmin,int ymax,int xmax,chtype v,chtype h)
  50. {
  51.     chtype    l;        /* border chars */
  52.     chtype    r;
  53.     chtype    t;
  54.     chtype    b;
  55.     chtype    tl;
  56.     chtype    tr;
  57.     chtype    bl;
  58.     chtype    br;
  59.     chtype    vattr;
  60.     chtype    hattr;
  61.     int    i;
  62.  
  63. #ifdef PDCDEBUG
  64.     if (trace_on) PDC_debug("wbox() - called\n");
  65. #endif
  66.  
  67.     if (win == (WINDOW *)NULL)
  68.         return( ERR );
  69.     if (ymax == 0)
  70.         ymax = win->_maxy - 1;
  71.     if (xmax == 0)
  72.         xmax = win->_maxx - 1;
  73.  
  74.     if ((ymin >= win->_maxy) ||
  75.         (ymax > win->_maxy) ||
  76.         (xmin >= win->_maxx) ||
  77.         (xmax > win->_maxx) ||
  78.         (ymin >= ymax) ||
  79.         (xmin >= xmax))
  80.     {
  81.         return (ERR);
  82.     }
  83.  
  84. #ifdef CHTYPE_LONG
  85.     if (v & A_ALTCHARSET)
  86.         {
  87.         l = r = (v & A_CHARTEXT) | A_ALTCHARSET;
  88.         t = b = (h & A_CHARTEXT) | A_ALTCHARSET;
  89.         }
  90.     else
  91.         {
  92.         l = r    = v & A_CHARTEXT;
  93.         t = b    = h & A_CHARTEXT;
  94.         }
  95. #else
  96.     l = r    = v & A_CHARTEXT;
  97.     t = b    = h & A_CHARTEXT;
  98. #endif
  99.  
  100. /* if the incoming character doesn't have its own attribute
  101.    then    use the    current    attributes for the window.
  102.    if the incoming character has attributes but    not a colour
  103.    component, or the attributes    to the current attributes
  104.    for the window.
  105.    if the incoming character has a colour component use    the
  106.    attributes solely from the incoming character */
  107.  
  108.     if ((h    & A_ATTRIBUTES)    == 0)
  109.        hattr    = win->_attrs;
  110.     else
  111.        if ((h & A_COLOR) == 0)
  112.           hattr = (h & A_ATTRIBUTES) | win->_attrs;
  113.        else
  114.           hattr = (h & A_ATTRIBUTES);
  115.  
  116.     if ((v    & A_ATTRIBUTES)    == 0)
  117.        vattr    = win->_attrs;
  118.     else
  119.        if ((v & A_COLOR) == 0)
  120.           vattr = (v & A_ATTRIBUTES) | win->_attrs;
  121.        else
  122.           vattr = (v & A_ATTRIBUTES);
  123.  
  124.     tl = tr = bl = br = l;        /* default same as vertical         */
  125.  
  126. #ifndef UNIX
  127.     if (l == 0xba)            /* vertical double bars             */
  128.     {
  129.         if (t == 0xcd)        /* horizontal too?             */
  130.         {
  131.             tl = 0xc9;    /* use double bar corners         */
  132.             tr = 0xbb;
  133.             bl = 0xc8;
  134.             br = 0xbc;
  135.         }
  136.         else
  137.         {
  138.             tl = 0xd6;       /* use horz-s vert-d corners         */
  139.             tr = 0xb7;
  140.             bl = 0xd3;
  141.             br = 0xbd;
  142.         }
  143.     }
  144. #endif
  145.  
  146.     if (l == ACS_VLINE)               /* vertical single bars         */
  147.     {
  148. #ifndef UNIX
  149.         if (t == 0xcd)
  150.         {
  151.             tl = 0xd5;       /* horizontal double bars         */
  152.             tr = 0xb8;
  153.             bl = 0xd4;
  154.             br = 0xbe;
  155.         }
  156.         else
  157. #endif
  158.         {
  159.             tl = ACS_ULCORNER;       /* use horz-s vert-s bars         */
  160.             tr = ACS_URCORNER;
  161.             bl = ACS_LLCORNER;
  162.             br = ACS_LRCORNER;
  163.         }
  164.     }
  165.  
  166.     /*
  167.      * wborder() settings override parms
  168.      */
  169.     if (win->_borderchars[0]) l  = win->_borderchars[0];
  170.     if (win->_borderchars[1]) r  = win->_borderchars[1];
  171.     if (win->_borderchars[2]) t  = win->_borderchars[2];
  172.     if (win->_borderchars[3]) b  = win->_borderchars[3];
  173.     if (win->_borderchars[4]) tl = win->_borderchars[4];
  174.     if (win->_borderchars[5]) tr = win->_borderchars[5];
  175.     if (win->_borderchars[6]) bl = win->_borderchars[6];
  176.     if (win->_borderchars[7]) br = win->_borderchars[7];
  177.  
  178.     if  (!(v|h) && !(l|r|t|b|tl|tr|bl|br))
  179.     {
  180.         /*
  181.          *    Appropriate default:
  182.          *
  183.          *    Single box with parent window's title attribute
  184.          */
  185.         l  = r = ACS_VLINE | win->_title_attr;
  186.         t  = b = ACS_HLINE | win->_title_attr;
  187.         tl = ACS_ULCORNER | win->_attrs;
  188.         tr = ACS_URCORNER | win->_attrs;
  189.         bl = ACS_LLCORNER | win->_attrs;
  190.         br = ACS_LRCORNER | win->_attrs;
  191.     }
  192.  
  193.     for (i = xmin + 1; i <= xmax - 1; i++)
  194.     {
  195.         win->_y[ymin][i] = (t | hattr);
  196.         win->_y[ymax][i] = (b | hattr);
  197.     }
  198.  
  199.     for (i = ymin + 1; i <= ymax - 1; i++)
  200.     {
  201.         win->_y[i][xmin] = (l | vattr);
  202.         win->_y[i][xmax] = (r | vattr);
  203.     }
  204.  
  205.     win->_y[ymin][xmin] = (tl | vattr);
  206.     win->_y[ymin][xmax] = (tr | vattr);
  207.     win->_y[ymax][xmin] = (bl | vattr);
  208.     win->_y[ymax][xmax] = (br | vattr);
  209.  
  210.     for (i = ymin; i <= ymax; i++)
  211.     {
  212.         if (win->_firstch[i] == _NO_CHANGE)
  213.         {
  214.             win->_firstch[i] = xmin;
  215.             win->_lastch[i] = xmax;
  216.         }
  217.         else
  218.         {
  219.             win->_firstch[i] = min(win->_firstch[i], xmin);
  220.             win->_lastch[i] = max(win->_lastch[i], xmax);
  221.         }
  222.     }
  223.     /*
  224.      * set wborder() settings to current values
  225.      */
  226.     win->_borderchars[0] = l  | vattr;
  227.     win->_borderchars[1] = r  | vattr;
  228.     win->_borderchars[2] = t  | hattr;
  229.     win->_borderchars[3] = b  | hattr;
  230.     win->_borderchars[4] = tl | vattr;
  231.     win->_borderchars[5] = tr | vattr;
  232.     win->_borderchars[6] = bl | vattr;
  233.     win->_borderchars[7] = br | vattr;
  234.     return (OK);
  235. }
  236.